package com.softeem.iov.controller;

import cn.hutool.core.lang.Console;
import com.softeem.iov.dto.R;
import com.softeem.iov.entity.Admin;
import com.softeem.iov.service.IAdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindException;
import org.springframework.validation.FieldError;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.validation.Valid;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 管理员表 前端控制器
 * </p>
 *
 * @author softeem
 * @since 2023-09-19
 */
@CrossOrigin  //开启跨域请求（允许来自不同源的请求）
@RestController
@RequestMapping("/iov/admin")
public class AdminController {

    @Autowired
    private IAdminService adminService;

    /**
     * 管理员列表
     *
     * @return
     */
    @GetMapping("/list/{page}/{limit}")
    public R list(@PathVariable(required = true) Integer page, @PathVariable(required = true) Integer limit) {
        return adminService.queryAll(page, limit);
    }

    /**
     * 管理员登录
     *
     * @param admin
     * @return
     */
    @PostMapping("/login")
    public R login(@Valid Admin admin) {
        System.out.println(admin);
        return adminService.login(admin);
    }

    /**
     * 管理员添加
     *
     * @param admin
     * @return
     */
    @PostMapping("/add")
    public R add(@Valid Admin admin) {
        return adminService.add(admin);
    }

    /**
     * 管理员信息修改
     *
     * @param admin
     * @return
     */
    @PutMapping("/update")
    public R update(Admin admin) {
        return adminService.modify(admin);
    }

}
